Page({
  /**
   * 页面的初始数据  
   */
  data: {
    indexList: ['距离排序', '所在区域', '所在行业', '产业集群', '征信评分', '科创标签', '科创评分'],
    origList: [{
        title: "距离排序",
        value: [],
        checked: false,
        multiple: false,
        children: [{
            value: '1',
            label: '距离较近',
            disabled: false,
          },
          {
            value: '2',
            label: '不限距离',
            disabled: false,
          },
        ],
        showAll: false,
        key: 'type'
      },
      {
        title: "所在区域",
        value: [],
        checked: false,
        multiple: false,
        children: [{
            value: '高新区',
            label: '高新区',
            disabled: false,
          },
          {
            value: '吴中区',
            label: '吴中区',
            disabled: false,
          },
          {
            value: '相城区',
            label: '相城区',
            disabled: false,
          },
          {
            value: '姑苏区',
            label: '姑苏区',
            disabled: false,
          },
          {
            value: '吴江区',
            label: '吴江区',
            disabled: false,
          },
          {
            value: '工业园区',
            label: '工业园区',
            disabled: false,
          },
          {
            value: '常熟市',
            label: '常熟市',
            disabled: false,
          },
          {
            value: '张家港市',
            label: '张家港市',
            disabled: false,
          },
          {
            value: '昆山市',
            label: '昆山市',
            disabled: false,
          },
          {
            value: '太仓市',
            label: '太仓市',
            disabled: false,
          },
        ],
        showAll: true,
        key: 'region'
      },
      {
        title: "所在行业",
        value: [],
        checked: false,
        multiple: false,
        children: [{
            value: '居民服务、修理和其他服务业',
            label: '居民服务、修理和其他服务业',
            disabled: false,
          },
          {
            value: '信息传输、软件和信息技术服务业',
            label: '信息传输、软件和信息技术服务业',
            disabled: false,
          },
          {
            value: '卫生和社会工作',
            label: '卫生和社会工作',
            disabled: false,
          },
          {
            value: '建筑业',
            label: '建筑业',
            disabled: false,
          },
          {
            value: '交通运输、仓储和邮政业',
            label: '交通运输、仓储和邮政业',
            disabled: false,
          },
          {
            value: '其他',
            label: '其他',
            disabled: false,
          },
          {
            value: '农、林、牧、渔业',
            label: '农、林、牧、渔业',
            disabled: false,
          },
          {
            value: '租赁和商务服务业',
            label: '租赁和商务服务业',
            disabled: false,
          },
          {
            value: '制造业',
            label: '制造业',
            disabled: false,
          },
          {
            value: '教育',
            label: '教育',
            disabled: false,
          },
          {
            value: '住宿和餐饮业',
            label: '住宿和餐饮业',
            disabled: false,
          },
          {
            value: '批发和零售业',
            label: '批发和零售业',
            disabled: false,
          },
          {
            value: '采矿业',
            label: '采矿业',
            disabled: false,
          },
          {
            value: '电力、热力、燃气及水生产和供应业',
            label: '电力、热力、燃气及水生产和供应业',
            disabled: false,
          },
          {
            value: '金融业',
            label: '金融业',
            disabled: false,
          },
          {
            value: '科学研究和技术服务业',
            label: '科学研究和技术服务业',
            disabled: false,
          },
          {
            value: '水利、环境和公共设施管理业',
            label: '水利、环境和公共设施管理业',
            disabled: false,
          },
          {
            value: '房地产业',
            label: '房地产业',
            disabled: false,
          },
        ],
        showAll: true,
        key: "industry"
      },
      {
        title: "产业集群",
        value: [],
        checked: false,
        multiple: false,
        children: [{
            value: '电子信息产业',
            label: '电子信息',
            disabled: false,
          },
          {
            value: '装备制造产业',
            label: '装备制造',
            disabled: false,
          },
          {
            value: '生物医药产业',
            label: '生物医药',
            disabled: false,
          },
          {
            value: '先进材料产业',
            label: '先进材料',
            disabled: false,
          },
          {
            value: '新能源汽车产业',
            label: '新能源汽车',
            disabled: false,
          },
          {
            value: '集成电路产业',
            label: '集成电路',
            disabled: false,
          },
        ],
        showAll: true,
        key: 'industrialCluster'
      },
      {
        title: "征信评分",
        value: [],
        checked: false,
        multiple: false,
        children: [],
        showAll: false,
        startScore: '',
        endScore: '',
      },
      {
        title: "科创标签",
        value: [],
        checked: false,
        multiple: true,
        children: [{
            value: '专精特新小巨人',
            label: '专精特新小巨人'
          },
          {
            value: '专精特新中小企业',
            label: '专精特新中小企业'
          },
          {
            value: '创新型中小企业',
            label: '创新型中小企业'
          },
          {
            value: '科技型中小企业',
            label: '科技型中小企业'
          },
          {
            value: '民营科技企业',
            label: '民营科技企业'
          },
          {
            value: '企业工程技术研究中心',
            label: '企业工程技术研究中心'
          },
          {
            value: '瞪羚企业',
            label: '瞪羚企业'
          },
          {
            value: '苏州市瞪羚计划企业',
            label: '苏州市瞪羚计划企业'
          },
          {
            value: '企业技术中心',
            label: '企业技术中心'
          },
          {
            value: '技术创新示范企业',
            label: '技术创新示范企业'
          },
          {
            value: '独角兽企业',
            label: '独角兽企业'
          },
          {
            key: 'kcList',
            value: '独角兽培育企业',
            label: '独角兽培育企业'
          },
          {
            value: '全球独角兽榜',
            label: '全球独角兽榜'
          },
          {
            value: '园区领军人才项目',
            label: '园区领军人才项目'
          },
          {
            value: '创新创业领军人才计划',
            label: '创新创业领军人才计划'
          },
          {
            value: '民营企业创新100强',
            label: '民营企业创新100强'
          },
          {
            value: '创新型领军企业',
            label: '创新型领军企业'
          },
          {
            value: '隐形冠军',
            label: '隐形冠军'
          }
        ],
        showAll: true,
        key: 'kcLabels'
      },
      {
        title: "科创评分",
        value: [],
        checked: false,
        multiple: false,
        children: [],
        showAll: false,
        startScore: '',
        endScore: '',
      },
    ],
    useList: [],
  },

  /**
   * 方法集合 
   */
  async initCydn() {
    const list = wx.getStorageSync('js_filter') || ''
    console.log(list,'list999')
    this.data.useList = list ? list : JSON.parse(JSON.stringify(this.data.origList))
    this.setData({
      useList: this.data.useList
    })
    console.log(this.data.useList, 'useListuseListuseListuseList');
  },
  searchInput(e) {
    const theOne = this.data.useList.find(pre => pre.title === e.currentTarget.dataset.title)
    if (e.currentTarget.dataset.value === 'end') {
      theOne.endScore = e.detail.value
    } else {
      theOne.startScore = e.detail.value
    }
    this.setData({
      useList: this.data.useList
    })
  },
  goConfirm() {
    const theOne = this.data.useList.find(pre => pre.title === '科创评分')
    if (theOne.endScore || theOne.startScore) {
      if (+theOne.startScore > +theOne.endScore) {
        wx.showToast({
          title: '请合理输入科创评分值',
          icon: 'none'
        })
        return
      }
    }
    const theOne_js = this.data.useList.find(pre => pre.title === '征信评分')
    if (theOne_js.endScore || theOne_js.startScore) {
      if (+theOne_js.startScore > +theOne_js.endScore) {
        wx.showToast({
          title: '请合理输入征信评分分值',
          icon: 'none'
        })
        return
      }
    }
    wx.setStorageSync('js_filter', this.data.useList)
    let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
      prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
        needFresh: true
      })
      wx.navigateBack({
        delta: 1 // 返回上一级页面。
      })
  },
  reData() {
    wx.setStorageSync('js_filter', '')
    this.setData({
      useList: JSON.parse(JSON.stringify(this.data.origList))
    })
  },
  toChange(e) {
    const title = e.currentTarget.dataset.title
    const theOne = this.data.useList.find(val => val.title === title)
    theOne.checked = !theOne.checked
    if (theOne.checked) {
      theOne.value = theOne.children.map(pre => pre.value)
    } else {
      theOne.value = []
    }
    this.setData({
      useList: this.data.useList
    })
  },
  selectOne(e) {
    const title = e.currentTarget.dataset.title
    const value = e.currentTarget.dataset.value
    const theOne = this.data.useList.find(val => val.title === title)
    const fOneIndex = theOne.value.findIndex(pre => pre === value)
    if (theOne.multiple) {
      if (fOneIndex > -1) {
        theOne.value.splice(fOneIndex, 1)
      } else {
        theOne.value.push(value)
      }
    } else {
      if (fOneIndex > -1) {
        theOne.value = []
      } else {
        theOne.value = []
        theOne.value.push(value)
      }
    }
    if (theOne.value.length === theOne.children.length) {
      theOne.checked = true
    } else {
      theOne.checked = false
    }
    this.setData({
      useList: this.data.useList
    })
  },
  // const res = await getSearchItem({});
  // const result = await getSearchItem1({});
  // const chanye = await queryMainPageSeachItem({});
  async getSearchItem() {
    const res = await getApp().globalData.request_cydn('/kcorpInfo/industry/getSearchItem', {},
      "POST")
    return res.data
  },
  async getIndustryCo() {
    const res = await getApp().globalData.request_cydn('/kcorpInfo/industry/getIndustryCo', {},
      "POST")
    return res.data
  },
  async queryMainPageSeachItem() {
    const res = await getApp().globalData.request_cydn('/industry/dnBase/queryMainPageSeachItem', {},
      "POST")
    return res.data
  },
  async getLabAndCount() {
    const res = await getApp().globalData.request_cydn('/kcorpInfo/industry/getLabAndCount', {},
      "POST")
    return res.data
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options,'optionsoptions')
    if(options.chaeckType=='false'){
      console.log('倒这里了')
      this.reData()
    }
    this.initCydn()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})